﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Alma.Core
{
    public interface ISearchExpressionProcessor
    {
        void Process(SearchAnd ex);
        void Process(SearchOr ex);
        void Process(SearchNot ex);
        void Process(SearchWord ex);
        void Process(SearchSelector ex);
        void Process(SearchCriterion ex);
        void Process(SearchRequest ex);
    }

    public abstract class SearchExpression
    {
        public abstract void Accept(ISearchExpressionProcessor p);
    }

    public class SearchAnd : SearchExpression
    {
        public SearchExpression Left { get; set; }
        public SearchExpression Right { get; set; }

        public override void Accept(ISearchExpressionProcessor p)
        {
            p.Process(this);
        }
    }

    public class SearchOr : SearchExpression
    {
        public SearchExpression Left { get; set; }
        public SearchExpression Right { get; set; }

        public override void Accept(ISearchExpressionProcessor p)
        {
            p.Process(this);
        }
    }

    public class SearchNot : SearchExpression
    {
        public SearchExpression Inner { get; set; }

        public override void Accept(ISearchExpressionProcessor p)
        {
            p.Process(this);
        }
    }

    public class SearchWord : SearchExpression
    {
        public string Value { get; set; }

        public override void Accept(ISearchExpressionProcessor p)
        {
            p.Process(this);
        }
    }

    public class SearchSelector : SearchExpression
    {
        public string Selector { get; set; }
        public string Value { get; set; }


        public override void Accept(ISearchExpressionProcessor p)
        {
            p.Process(this);
        }
    }

    public class SearchCriterion : SearchExpression
    {
        public string Criterion { get; set; }
        public string Operator { get; set; }
        public string Value { get; set; }

        public override void Accept(ISearchExpressionProcessor p)
        {
            p.Process(this);
        }
    }

    public class SearchRequest : SearchExpression
    {
        public SearchExpression Expression { get; set; }

        public override void Accept(ISearchExpressionProcessor p)
        {
            p.Process(this);
        }
    }
}
